Inside Macintosh: Sound

| Previous | Chapter contents | Chapter top | Section top | Next |

Obtaining Information About All Sound Channels

You can use the SndManagerStatus function to determine information about all the sound channels that are currently allocated by all applications. For example, you can use this function to determine how many channels are currently allocated. One of the parameters required by the SndManagerStatus function is a pointer to a Sound Manager status record, which you must allocate before calling SndManagerStatus . A Sound Manager status record has this structure:

TYPE SMStatus =
PACKED RECORD
    smMaxCPULoad:           Integer;        {maximum load on all channels}
    smNumChannels:          Integer;        {number of allocated channels}
    smCurCPULoad:           Integer;        {current load on all channels}
END;

The smNumChannels field contains the number of sound channels currently allocated. This does not mean that the channels are actually being used, only that they have been created with the SndNewChannel function and not yet disposed.

The Sound Manager uses information that it returns in the smMaxCPULoad and smCurCPULoad fields to help it determine whether it can allocate a new channel when your application calls the SndNewChannel function. The Sound Manager sets smMaxCPULoad to a default value of 100 at startup time, and the smCurCPULoad field reflects the approximate percentage of CPU processing power currently taken by allocated sound channels.

Your application should not reply on the values returned in the smMaxCPULoad and smCurCPULoad fields. To determine if it is safe to allocate a channel, simply try to allocate it with the SndNewChannel function. That function returns the appropriate result code if allocating the channel would put too much of a strain on CPU processing.

Listing 1-24 illustrates the use of SndManagerStatus . It defines a function that returns the number of sound channels currently allocated by all applications.

Listing 24 Determining the number of allocated sound channels

FUNCTION MyGetNumChannels: Integer;
VAR
    myErr:              OSErr;
    mySMStatus:         SMStatus;
BEGIN
    MyGetNumChannels := 0;
    myErr := SndManagerStatus (Sizeof(SMStatus), @mySMStatus);
    IF myErr = noErr THEN
        MyGetNumChannels := mySMStatus.smNumChannels;
END;

© 1998 Apple Computer, Inc.

| Previous | Chapter contents | Chapter top | Section top | Next |